package com.cirnoworks.guice;

import com.google.inject.TypeLiteral;
import com.google.inject.spi.InjectionListener;
import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;

class LifeCycleListener implements TypeListener {

	private LifeCycleInjectionListener listener;

	LifeCycleListener(LifeCycleService service) {
		listener = new LifeCycleInjectionListener(service);
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> void hear(TypeLiteral<T> type, TypeEncounter<T> encounter) {
		if (LifeCycle.class.isAssignableFrom(type.getRawType())) {
			encounter.register(((InjectionListener<? super T>) listener));
		}
	}
}